<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="../../js/tools/jquery-1.4.2.min.js"></script>
<style>
table{table-layout:fixed;font-size:12px;}
  tr{background-color:#F1F6F6;}
  td{border:1px solid #D9D9D9;color:black;padding:2px;}
</style>
<script>
$(document).ready(function(){
    $.post("../../groupbyajax/dic!getProvince.action",function(data)
     {
         $("#province").html(data.province);
     });
});
 function changeValidateCode(obj) {     
        var timenow = new Date().getTime();    
        obj.src="groupbyajax/rand.action?d="+timenow;   
    }   
    
 var isSuccessEmail=false;
 function checkUserEmail()
 {
    var email=$.trim($("input[name='email']").val());
     var str = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
     $("#errorInfor").remove();      
     
    if(email=="")
    {
      alert("Email 不能为空！");
      isSuccessEmail=false;
    }else if(!str.test(email))
    {
      alert("Email 格式不对！");
      isSuccessEmail=false;
    }else
    {
       
	    $.getJSON("../../groupbyajax/user!checkUserEmail.action",{email:email},function(data){
            var div='';
            if(!data.success)
            {
               isSuccessEmail=true;
               
               div="<span id='errorInfor' ><font color='blue'>Email 可以使用！</font></span>";
            }else
            {
               isSuccessEmail=false;
               div="<span id='errorInfor' ><font color='red'>Email 已经存在，请用其它的！</font></span>";
            }
            $("input[name='email']").after(div); 
            
	    });
    }
    return isSuccessEmail;
 }
 function getCity(pid)
 {
   $.post("../../groupbyajax/dic!getCity.action",{id:pid},function(data)
     {
         $("#cityId").html(data.city);
     });
     
 }
  var isSuccessRand=false;
 
 
 function checkForm()
 {
       checkUserEmail();
       
       if(!isSuccessEmail)
       {
          return false;
       }
       var password=$.trim($("input[name='password']").val());
       var password2=$.trim($("input[name='password2']").val());
       
       if(password==""||password2==""||password!=password2)
       {
          alert("密码为空或两输入密码不一致！");
          return false;
       }else if(password.length<5||password.length>15)
       {
          alert("密码长度在5~15！");
          return false;
       }
       var city=$("#cityId").val();
       
       if(city==null)
       {
          alert("请选择城市！");
          return false;
       }
       $("#userForm").submit();
 }
 function category()
 {
      var date=new Date();
       $.getJSON("../../groupbyajax/dic!getCategoryList.action?dateTime="+date.getTime(),{flag:3},function(data)
	     {
	     
	       var category="";
	       for(var i=0;i<data.category.length;i++)
	       {
	         category+="<option value='"+data.category[i].id+"'>"+data.category[i].categoryName+"</option>";
	       }
	      
	         $("#categoryId").html(category);
	     });
 }
 
</script>
</head>

<body>
<form id="userForm" action="user!addUser.action" method="post" >	
	<table  style="width:80%;" align="center">
 <tr><td align="center"><font size=5>添加用户</font></td></tr>
 <tr><td>用户类型:<select name="level" size="1" onchange="if($(this).val()==4){$('#cid').show();category();}else{$('#cid').hide();}">
        <option value="3">团购用户</option>
        <option value="4">品牌用户</option>
      </select></td></tr>
  <tr id="cid" style="display:none">
    <td height="35"><span class="input_ziti">品牌分类：</span><label>
      <select name="categoryIds" id="categoryId" style="width:100px;height:100px;" multiple="multiple">
      </select>
    </label>
	</td>
  </tr>
 <tr><td>电子邮箱：<input name="email" type="text" size="30" onblur="checkUserEmail()" /></td></tr>
 <tr><td>密&nbsp;&nbsp;&nbsp;&nbsp;码:<input name="password" type="password" size="30" /></td></tr>
  <tr><td>密码确认:<input name="password2" type="password" size="30" /></td></tr>
<tr>
    <td height="35"><label>
      省：<select name="province" id="province" style="width:100px;" onchange="getCity($(this).val())"></select>
    </label><label>
      市：<select name="city" id="cityId" style="width:100px;"></select>
    </label></td>
</tr>
<tr>
    <td  align="center">
       <input type="button" onclick="checkForm()" value="添加">
    </td>
</tr>
</table>
</form>

</body>
</html>
